package com.ajie.bluetoothcard.ui;


import com.ajie.bluetoothcard.db.DBApi;
import com.ajie.bluetoothcard.domain.Card;
import com.ajie.bluetoothcard.pre.Preference;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

/**
 * @author liujie
 *  @Date: 2013-12-04
 * @version 1.0.0
 */
public class WelcomeActivity extends Activity {

	private static final int GO_HOME = 1000;
	// 延迟3秒
	private static final long SPLASH_DELAY_MILLIS = 1000;


	/**
	 * Handler:跳转到不同界面
	 */
	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case GO_HOME:
				goGuide();
				break;
			}
			super.handleMessage(msg);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		DBApi dbApi = DBApi.getInstance(this);
		new Preference(this);
		if(Preference.getInstance().getIsFirst_insert()){
			Preference.getInstance().setFIRST_INSERT(false);
			Card card = new Card("阿洁","15155882250","345678","","部长","国防部","01.amr","天安门","2","1","www.baidu.com","123@qq.com","");
			Card card1 = new Card("周瑜","15155881123","123456","","政协","国防部","","天安门","2","0","www.baidu.com","er43@qq.com","");
			Card card2 = new Card("诸葛亮","15134582250","189034","","部长","国防部","01.amr","天安门","3","0","www.baidu.com","21354@qq.com","");
			Card card3 = new Card("张飞","13555882250","137680","","部长","国防部","","天安门","4","0","","www.baidu.com","367@qq.com");
			Card card4 = new Card("关羽","12654582250","14689","","部长","国防部","01.amr","天安门","5","","","","");
			Card card5 = new Card("刘德华","15098882250","","","部长","国防部","01.amr","天安门","2","0","","","");
			Card card6 = new Card("李连杰","15234682250","87640","","部长","国防部","","天安门","3","0","www.baidu.com","2367@qq.com","");
			Card card7 = new Card("张曼玉","1510876250","","","部长","国防部","01.amr","天安门","2","1","","","");
			Card card8 = new Card("小张","1510872450","","","部长","国防部","01.amr","天安门","1","0","","","");
			Card card9 = new Card("小王","1510873450","","","部长","国防部","01.amr","天安门","1","1","","","");
			dbApi.insertCard(card);
			dbApi.insertCard(card1);
			dbApi.insertCard(card2);
			dbApi.insertCard(card3);
			dbApi.insertCard(card4);
			dbApi.insertCard(card5);
			dbApi.insertCard(card6);
			dbApi.insertCard(card7);
			dbApi.insertCard(card8);
			dbApi.insertCard(card9);
		}
		
		mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS);
	}

	private void goGuide() {
		Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
		WelcomeActivity.this.startActivity(intent);
		WelcomeActivity.this.finish();
	}
}
